package io.renren.controller;

import io.renren.common.utils.Result;
import io.renren.service.WxPayService;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @ClassName ApiWxPayController
 * @Description TODO
 * @Author Jll
 * @Date 2024/6/18 16:28
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/wx")
@Slf4j
public class ApiWxPayController {


    @Resource
    private WxPayService wxPayService;



    /**
     * 合作伙伴Native下单
     * @return
     * @throws Exception
     */
    @PostMapping("/partnerPaymentsNativePay")
    public Result<Map<String, Object>> partnerPaymentsNativePay() throws Exception {
        log.info("发起合伙人partnerPaymentsNativePay支付请求 v3");
        //返回支付二维码连接和订单号
        Map<String, Object> map = wxPayService.partnerPaymentsNativePay();
        return new Result().ok(map);
    }

    /**
     * 支付通知
     * 微信支付通过支付通知接口将用户支付成功消息通知给商户
     */
    @PostMapping("/payCallback")
    public void payCallback(HttpServletRequest request, HttpServletResponse response) throws IOException {
        wxPayService.payCallback(request, response);
    }


    /**
     * 合作伙伴商户订单号查询订单
     * @return
     * @throws Exception
     */
    @GetMapping("/queryOrderByOutTradeNo")
    public Result<Map<String, Object>> queryOrderByOutTradeNo(@RequestParam String outTradeNo) throws Exception {
        Map<String, Object> map = wxPayService.queryOrderByOutTradeNo(outTradeNo);
        return new Result().ok(map);
    }







}
